import mysql.connector
import os

class MysqlConnectInstance():
    _instance = None




    def __new__(cls, *args, **kwargs):
        if not cls._instance:
            cls._instance = super(MysqlConnectInstance, cls).__new__(cls)
        return cls._instance

    def __init__(self):
        db_host = os.getenv('DB_HOST', 'localhost')
        db_user = os.getenv('DB_USER', 'root')
        db_password = os.getenv('DB_PASSWORD', 'root')
        db_name = os.getenv('DB_NAME', 'ex_rate')

        if not hasattr(self, 'initialized'):
            self.initialized = True
            self._instance = mysql.connector.connect(
                host= db_host,  # 替换为你的主机名
                database= db_name,  # 替换为你的数据库名
                user= db_user,  # 替换为你的用户名
                password= db_password  # 替换为你的密码
            )

    def get_connection(self):
        return self._instance
